package com.xbongbong.saas.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * saas各业务对应数据库表名的枚举
 *
 * @author chaoxiong.lei
 * @date 2019/1/15 14:42
 */
@Getter
public enum BusinessTableNameEnum {
    // 采购退货单
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), "tb_saas_returned_purchase"),
    //客户
    CUSTOMER(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "tb_saas_customer"),
    // 出库单
    OUTSTOCK(XbbRefTypeEnum.OUTSTOCK.getCode(), "tb_saas_outstock"),
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), "tb_saas_outstock"),
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), "tb_saas_outstock"),
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), "tb_saas_outstock"),
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), "tb_saas_outstock"),
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), "tb_saas_outstock"),
    // 机会
    OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), "tb_saas_opportunity"),
    // BOM单
    BOM(XbbRefTypeEnum.BOM_BILL.getCode(), "tb_saas_bom"),
    // 工作报告
    WORK_REPORT(XbbRefTypeEnum.WORK_REPORT.getCode(), "tb_saas_work_report"),
    // 访客计划
    COMMUNICATE_PLAN(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), "tb_saas_communicate_plan"),
    // 客户跟进记录
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), "tb_saas_customer_communicate"),
    // 供应商跟进记录
    SUPPLIER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), "tb_saas_supplier_communicate"),
    // 合同
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), "tb_saas_contract"),
    // 生产单
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), "tb_saas_production_order"),
    // 回款
    PAYMENT(XbbRefTypeEnum.PAYMENT.getCode(), "tb_saas_payment"),
    // 回款单
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), "tb_saas_payment_sheet"),
    // 付款计划
    PAY_PLAN(XbbRefTypeEnum.PAY_PLAN.getCode(), "tb_saas_pay_plan"),
    // 付款单
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET.getCode(), "tb_saas_pay_sheet"),
    // 发票
    INVOICE(XbbRefTypeEnum.INVOICE.getCode(), "tb_saas_invoice"),
    //进项发票
    PURCHASE_INVOICE(XbbRefTypeEnum.PURCHASE_INVOICE.getCode(),"tb_saas_purchase_invoice"),
    // 盘点单
    INVENTORY(XbbRefTypeEnum.INVENTORY.getCode(), "tb_saas_inventory"),
    // 调拨单
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), "tb_saas_transfer"),
    // 入库单
    INSTOCK(XbbRefTypeEnum.INSTOCK.getCode(), "tb_saas_instock"),
    // 采购入库单
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), "tb_saas_instock"),
    // 其他入库单
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), "tb_saas_instock"),
    // 退货入库单
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), "tb_saas_instock"),
    //  生产入库单
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), "tb_saas_instock"),
    // 生产退料单
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(),"tb_saas_instock" ),
    // 仓库
    WAREHOUSE(XbbRefTypeEnum.WAREHOUSE.getCode(), "tb_saas_warehouse"),
    // 仓库产品
    WAREHOUSE_PRODUCT(XbbRefTypeEnum.WAREHOUSE_PRODUCT.getCode(), "tb_saas_warehouse_product"),
    // 联系人
    CONTACT(XbbRefTypeEnum.CONTACT.getCode(), "tb_saas_contact"),
    // 产品
    PRODUCT(XbbRefTypeEnum.PRODUCT.getCode(), "tb_saas_product"),
    // 采购合同
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), "tb_saas_purchase"),
    // 供应商
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), "tb_saas_supplier"),
    // 退货退款
    REFUND(XbbRefTypeEnum.REFUND.getCode(), "tb_saas_refund"),
    // 供应商联系人
    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), "tb_saas_supplier_contact"),
    // 装配出入库单
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), "tb_saas_assemble"),
    // 审批流程
    APPROVAL(XbbRefTypeEnum.APPROVAL.getCode(), "tb_paas_process_data"),
    //工单
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), "tb_saas_work_order_data"),
    //报价单
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), "tb_saas_quotation"),
    //报销单
    REIMBURSEMENT_FORM(XbbRefTypeEnum.REIMBURSEMENT_FORM.getCode(), "tb_saas_reimbursement_form"),
    //费用
    EXPENSE(XbbRefTypeEnum.EXPENSE.getCode(), "tb_saas_expense"),
    MARKET_ACTIVITY(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), "tb_saas_market_activity"),
    CLUE(XbbRefTypeEnum.CLUE.getCode(), "tb_saas_clue"),
    //回款计划
    PAYMENT_TASK(XbbRefTypeEnum.PAYMENT_TASK.getCode(),"tb_saas_payment_task"),
    UNKNOWN(404, "");

    private int code;
    private String tableName;

    BusinessTableNameEnum(int code, String tableName) {
        this.code = code;
        this.tableName = tableName;
    }

    /**
     * 通过枚举 code 获得枚举
     *
     * @param code 枚举Code
     *
     * @return BusinessTableNameEnum
     */
    public static BusinessTableNameEnum getByCode(Integer code) {
        for (BusinessTableNameEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<BusinessTableNameEnum>
     */
    public List<BusinessTableNameEnum> getAllEnum() {
        List<BusinessTableNameEnum> list = new ArrayList<>();
        for (BusinessTableNameEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }
}
